package com.dwjm.exam.stu_login;

import com.dwjm.exam.pojo.Student;
import com.dwjm.exam.utils.ConnectionDatabaseForMySQLUseJdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class StudentLoginDaoImpl  implements  StudentLoginDao{


    Connection connection = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    public StudentLoginDaoImpl() {
        connection = ConnectionDatabaseForMySQLUseJdbc.getConnection();

    }


//登录方法
    @Override
    public boolean login(String username, String password) {
       try{
           pstmt = connection.prepareStatement("select username from student where username= ? and password= ?");
           pstmt.setString(1, username);
           pstmt.setString(2, password);
           rset = pstmt.executeQuery();

           if(rset.next()){
               return true;
           }
       }catch (Exception e){
           e.printStackTrace();
       }
       return false;
    }
}
